from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QLabel, QSlider


class MusicSlider(QWidget):
    """管理音乐进度条的类"""
    def __init__(self, MP3Player):
        super().__init__()
        self.startTimeLabel = QLabel('00:00')
        self.endTimeLabel = QLabel('00:00')
        self.slider = QSlider(Qt.Horizontal, MP3Player)
        self.player = MP3Player.player

        # 参数必须为函数，故使用lambda创建一个匿名函数
        self.slider.sliderMoved[int].connect(lambda: self.player.setPosition(self.slider.value()))